import { NestFactory } from '@nestjs/core';
import { AppModule } from './app/app.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { NestExpressApplication } from '@nestjs/platform-express';
import * as config from './common/utils/config';
import { HttpExceptionFilter } from './middleware/http.filter';

const swaggerOptions = new DocumentBuilder()
  .setTitle('api文档')
  .setDescription('文档')
  .setVersion('1.0')
  .build();

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  const document = SwaggerModule.createDocument(app, swaggerOptions);

  if (config.isDebug) {
    SwaggerModule.setup('api-docs', app, document);
  }
  app.enableCors();
  // 异常拦截
  app.useGlobalFilters(new HttpExceptionFilter());

  await app.listen(4000);
}
bootstrap();
